<template>
<!-- <div class="bc"> -->
<div class="bc">
  <div>申请列表</div>
    <el-card v-for="item in applyList" :key="item.id">
        <div class="tc1">
          <div>申请用户:{{item.username}}</div>
          <div style="applydata">申请时间：   {{ dayjs(item.applydata).format("YYYY-MM-DD / HH:mm:ss") }}</div>
        </div>
        <div>
          <div>申请简介：</div>
          {{item.applySession}}
        </div>
        <div class="btn" v-if="item.role==2">
          <el-button type="danger" @click="btnrefuse(item)" >拒绝</el-button>
          <el-button type="success" @click="btnResive(item)" >通过</el-button>
        </div>
          <div class="btn" v-else-if="item.role==0">
          <el-button type="danger"  disabled>已拒绝</el-button>
        </div>
           <div class="btn" v-else-if="item.role==3">
          <el-button type="warning"  disabled>已撤销</el-button>
        </div>
        <div  class="btn" v-else>
          <el-button type="success" disabled >已通过</el-button>
        </div>
        <!-- <span></span> -->
    </el-card>
<!-- </div> -->
</div>
</template>

<script>
import { getAllApply, updateApply } from '@/api/applyAD'
import { update } from '@/api/user'
export default {
  data () {
    return {
      applyList: '',
      disabled: false,
      user: {
        id: '',
        active: ''
      },
      apply: {
        userId: '',
        role: ''
      }
    }
  },
  methods: {
    init () {
      getAllApply().then(response => {
        const { data } = response
        this.applyList = data
        console.log(this.applyList)
      })
    },
    btnrefuse (item) {
      this.user.id = item.userId
      this.user.active = false
      // this.apply.userId = item.userId
      this.apply.id = item.id
      this.apply.userId = item.userId
      this.apply.role = 0
      this.apply.status = 1
      console.log(this.apply)
      // // this.user.avatar = res.data

      updateApply(this.apply).then(res => {
        update(this.user).then(res => {
        })
        this.$message.error('已拒绝allpy申请')
        this.init()
      })
    },
    btnResive (item) {
      this.user.id = item.userId
      this.user.active = true
      // this.apply.userId = item.userId
      this.apply.id = item.id
      this.apply.userId = item.userId
      this.apply.role = 1
      this.apply.status = 1
      console.log(this.apply)

      updateApply(this.apply).then(res => {
        update(this.user).then(res => {
        })
        this.$message.success('已接受allpy申请')
        this.init()
      })
    }
  },
  created () {
    this.init()
  },
  components: {},
  mounted () {}
}
</script>

<style lang="less" scoped>
// .b-container{
//   padding: 10px;

// }
  .bc{
  padding: 10px;
  background-color: #fff;
  overflow: scroll;
  height: 100vh;
}
.tc1{
  display: flex;
  flex-direction: row;
  justify-content: space-between;

}
.btn{
  float: right;
  padding: 10px;
}
</style>
